package com.sgb.kjwl.viewmodel.self.publish;

import androidx.databinding.ObservableField;

import com.sgb.kjwl.api.APIManager;
import com.swgk.core.util.PickSelectEntity;
import com.sgb.kjwl.model.entity.user.AddCarEntity3;
import com.sgb.kjwl.model.entity.user.CommonPickerEntity3;
import com.sgb.kjwl.repository.SelfRepertory;
import com.sgb.kjwl.view.ui.activity.self.publish.CarPublishActivity2;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class CarPublishModel2 extends BaseViewModel {
    public ObservableField<AddCarEntity3> addCarEntity = new ObservableField<>(new AddCarEntity3());
    private CarPublishActivity2 activity;
    private SelfRepertory repertory;

    public CarPublishModel2(CarPublishActivity2 activity, SelfRepertory repertory) {
        this.activity = activity;
        this.repertory = repertory;
    }

    public void getPickercarRent() {
        APIManager.getInstance().getUserAPI().getDictCarRent().enqueue(new Callback<BaseEntity<List<CommonPickerEntity3>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<CommonPickerEntity3>>> call, Response<BaseEntity<List<CommonPickerEntity3>>> response) {
                if (response.body() != null && response.body().getState().equals("ok")) {
                    activity.showRentPicker(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<CommonPickerEntity3>>> call, Throwable t) {

            }
        });
    }

    //获取税率列表
    public void getLeaseRate() {
        APIManager.getInstance().getLeaseAPI().getLeaseRate().enqueue(new Callback<BaseEntity<List<PickSelectEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<PickSelectEntity>>> call, Response<BaseEntity<List<PickSelectEntity>>> response) {
                if (response.body() == null) return;
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    activity.showRate(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<PickSelectEntity>>> call, Throwable t) {
            }
        });
    }

}
